package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejianapp14.Activity.JavaBean.Comment;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by jason_lin on 2017/10/23.
 */

public class TieziInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List<Comment> mDataList;
    private LayoutInflater mLayoutInflater;

    public TieziInfoAdapter(Context mContext, List<Comment> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.commentcard,parent,false);
        return new TieziInfoAdapter.ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Comment entity = (Comment) mDataList.get(position);
        if (null == entity)
            return;
        TieziInfoAdapter.ViewHolder viewHolder = (TieziInfoAdapter.ViewHolder) holder;
        viewHolder.comment_time.setText(entity.getCtime());
        viewHolder.comment_content.setText(entity.getCcontent());
        viewHolder.comment_user_name.setText(entity.getUname());
        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/user/"+entity.getUpicture()).into(viewHolder.comment_user_pic);
    }
    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView comment_user_pic;
        TextView comment_time;
        TextView comment_user_name;
        TextView comment_content;
        LinearLayout comment_container;

        public ViewHolder(View itemView) {
            super(itemView);
            comment_user_name = (TextView) itemView.findViewById(R.id.comment_user_name) ;
            comment_user_pic =(ImageView) itemView.findViewById(R.id.comment_user_pic) ;
            comment_time = (TextView) itemView.findViewById(R.id.comment_time);
            comment_content = (TextView) itemView.findViewById(R.id.comment_content);
            comment_container = (LinearLayout) itemView.findViewById(R.id.comment_container);

        }
    }
}
